package com.grandtech.insurance.common;



import java.lang.reflect.Field;
import java.lang.reflect.Type;
import java.util.Date;

/**
 * Created by zy on 2017/1/23.
 * 基本类型转换
 */
public final class TransferUtil {
    private TransferUtil() {

    }
    public static Object string2SimpleObject(Field field, String s) {
        Object o = null;
        Type type = field.getType();
        try {
            if (null == s) {
                return null;
            } else if ("".equals(s)) {
                return null;
            } else if (type == Integer.class || type == int.class) {
                o = Integer.parseInt(s);
            } else if (type == Float.class || type == float.class) {
                o = Float.parseFloat(s);
            } else if (type == Double.class || type == double.class) {
                o = Double.parseDouble(s);
            } else if (type == Long.class || type == long.class) {
                o = Long.parseLong(s);
            } else if (type == Short.class || type == short.class) {
                o = Short.parseShort(s);
            } else if (type == String.class) {
                o = s;
            } else if (type == Date.class) {
                //o = DateUtil.strToDateTime(s);
            }
        } catch (Exception e) {
            o = null;
            e.printStackTrace();
        }
        return o;
    }
}
